package com.example.javamaday.leetcode;

public class LeetCodeTest0326 {

    public boolean isPowerOfThree(int n) {
        if (n < 1) {
            return false;
        }
        if (n == 1) {
            return true;
        }
        boolean result = true;
        while(n >= 3) {
            if (n % 3 != 0) {
                result = false;
                break;
            } else {
                n = n / 3;
            }
        }
        if (result) {
            if (n == 1) {
                result = true;
            } else {
                result = false;
            }
        }
        return result;
    }
}
